package cn.vehicle.controller;

import cn.vehicle.biz.SysRoleBiz;
import cn.vehicle.domains.vo.BasePage;
import cn.vehicle.domains.vo.Result;
import cn.vehicle.domains.vo.req.sysRole.AddRolePermissionReq;
import cn.vehicle.domains.vo.req.sysRole.RoleListReq;
import cn.vehicle.domains.vo.res.sysRole.SysRoleRes;
import cn.vehicle.domains.vo.req.sysRole.AddRoleReq;
import cn.vehicle.domains.vo.req.sysRole.UpdateRoleReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/role") // 与用户接口路径规范一致，前缀为/api/role
@Slf4j
@Tag(name = "SysRoleController", description = "角色管理相关接口")
public class SysRoleController {

    @Resource
    private SysRoleBiz sysRoleBiz;

    @PostMapping("/add")
    @Operation(description = "创建角色接口")
    public Result<Void> addRole(@RequestBody @Valid AddRoleReq req) {
        sysRoleBiz.addRole(req);
        return Result.success();
    }

    @PostMapping("/updateRole")
    @Operation(description = "更新角色接口")
    public Result<Void> updateRole(@RequestBody @Valid UpdateRoleReq req) {
        sysRoleBiz.updateRole(req);
        return Result.success();
    }

    @PostMapping("/deleteRole")
    @Operation(description = "删除角色接口")
    public Result<Void> deleteRole(
            @Parameter(schema = @Schema(name = "id", description = "角色ID"))
            @RequestParam Long id) {
        sysRoleBiz.deleteRole(id);
        return Result.success();
    }

    @PostMapping("/getRoleById")
    @Operation(description = "查询角色详情接口")
    public Result<SysRoleRes> getRoleById(
            @Parameter(schema = @Schema(name = "id", description = "角色ID"))
            @RequestParam Long id) {
        return Result.success(sysRoleBiz.getRoleById(id));
    }

    @PostMapping("/list")
    @Operation(description = "分页查询角色列表接口")
    public Result<BasePage<SysRoleRes>> list(@RequestBody @Valid RoleListReq req) {
        return Result.success(sysRoleBiz.list(req));
    }


    @PostMapping("/addRolePermissions")
    @Operation(description = "添加角色权限")
    public Result<Void> addRolePermissions(@RequestBody @Valid AddRolePermissionReq req) {
        sysRoleBiz.addRolePermissions(req);
        return Result.success();
    }

}
